package lib.bone.flow.module.processor.impl;

import cn.hutool.core.lang.Validator;
import lib.bone.flow.constant.FlowNodeTypeConst;
import lib.bone.flow.domain.dto.FlowParam;
import lib.bone.flow.domain.entity.FlowWork;
import lib.bone.flow.domain.model.BaseModel;
import lib.bone.flow.domain.model.FlowModel;
import lib.bone.flow.domain.model.StartModel;
import lib.bone.flow.event.FlowStartNodeEvent;
import lib.bone.flow.module.processor.FlowNodeProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: kindear
 */
@Slf4j
@Service
public class StartNodeProcessorImpl implements FlowNodeProcessor {
    @Autowired(required = false)
    FlowStartNodeEvent flowStartNodeEvent;
    @Override
    public String getNodeType() {
        //返回开始节点标记
        return FlowNodeTypeConst.START_NODE;
    }

    @Override
    public void process(FlowWork flowWork, FlowModel flowModel, BaseModel currentNddeModel, FlowParam flowParam) {
        if (Validator.isNotEmpty(flowStartNodeEvent)){
            StartModel startModel = flowModel.getStartModel();
            flowStartNodeEvent.onEvent(flowWork,startModel,flowParam);
        }
    }

    @Override
    public void back(FlowWork flowWork, FlowModel flowModel, BaseModel currentNddeModel, FlowParam flowParam) {
        log.warn("起始节点，无法倒退");
    }
}
